package test.my.com.myapplicationtest.animation_test;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewPropertyAnimator;
import android.view.WindowManager;
import android.view.animation.AnimationSet;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;

import test.my.com.myapplicationtest.R;

/**
 * Created by ah on 2017/1/19.
 */

public class AnimationActivity extends Activity {

    private ImageView image_iv,rotate_iv;
    private int mScreenWidth, mScreenHeight;
    ViewPropertyAnimator animator;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.aty_animation_test_layout);
        image_iv = (ImageView) findViewById(R.id.image_iv);
        rotate_iv = (ImageView) findViewById(R.id.rotate_iv);

        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        mScreenWidth = wm.getDefaultDisplay().getWidth();
        mScreenHeight = wm.getDefaultDisplay().getHeight();

        final float currentPositionY = image_iv.getTranslationY();
        final float currentPositionX = image_iv.getTranslationX();
        // 横向移动动画
//        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(
//                image_iv,
//                "translationX",
//                currentPositionX,
//                mScreenWidth);
//        objectAnimator.setRepeatCount(10000);
//        ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(
//                image_iv,
//                "translationY",
//                currentPositionY,
//                mScreenHeight);
//        objectAnimator1.setRepeatCount(10000);
//        final AnimatorSet animatorSet = new AnimatorSet();
//        animatorSet.setDuration(1000);
//        animatorSet.setInterpolator(new LinearInterpolator());
//        animatorSet.playTogether(objectAnimator,objectAnimator1);
//        animatorSet.start();



        ObjectAnimator roateAnimator = ObjectAnimator.ofFloat(rotate_iv,"rotationX",0,180);
        rotate_iv.setPivotX(0);
        rotate_iv.setPivotY(0);
        roateAnimator.setDuration(6000);
        roateAnimator.setRepeatCount(1000);
        roateAnimator.setInterpolator(new LinearInterpolator());
        roateAnimator.start();
    }

}
